#include <windows.h>
#include <iostream>
#include <conio.h>
  
using namespace std;
void ErrorView();
  
int main()
{
    DWORD status;
    char path[100]; GetCurrentDirectory(100, path);
    strcpy(path + strlen(path), "\\sys\\objchk_wxp_x86\\i386\\driver.sys");
    SC_HANDLE manager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS); 
    SC_HANDLE service = CreateService(manager,"driver",
              "driver",SERVICE_ALL_ACCESS,
              SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,
              path,0,0,0,0,0);
               


    StartService(service,0,0);
    HANDLE handle = CreateFile("\\\\.\\driver",GENERIC_READ|GENERIC_WRITE,
           FILE_SHARE_READ|FILE_SHARE_WRITE,
           NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    if(handle == INVALID_HANDLE_VALUE) return 1;
                                       
    DeviceIoControl(handle,0,0,0,0,0,&status,0);
    
    char out[] = "Buffer";
    DWORD outSize = sizeof(out);
    WriteFile(handle,out,outSize,&status,0);
    WriteFile(handle,out,outSize,&status,0);
    
    char in[3000];
    int inSize = sizeof(in);
    ReadFile(handle,in, inSize, &status, 0);
    cout << "Buffer is " << in;
    CloseHandle(handle);
    
    SERVICE_STATUS status_;
    ControlService(service,SERVICE_CONTROL_STOP,&status_);
    DeleteService(service);
    CloseServiceHandle(service);
    CloseServiceHandle(manager);
    while(!getch());
    return 0;
}
